package org.xindian.lbstest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Vector;

import org.xindian.lbstest.lbs.CDMACell;
import org.xindian.lbstest.lbs.GSMCell;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class LBSTestActivity extends Activity {
	private Button  btn_start;
	private Button  btn_stop;
	private ListView lv_list;
	private ArrayList<HashMap<String,String>> listData = new ArrayList<HashMap<String,String>>();
	private SimpleAdapter listAdapter;
	private LBSManager lbsManager;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        lbsManager=LBSManager.getInstance(this);
        
        btn_start = (Button)findViewById(R.id.btn_start);
        btn_stop = (Button)findViewById(R.id.btn_stop);
        lv_list = (ListView)findViewById(R.id.infoList);
        
        listAdapter = new SimpleAdapter(this, 
        								listData, 
        								R.layout.lbs_list_item,
        								new String[]{"type",        "lac",         "cid",          "timestamp"}, 
        								new int[]   {R.id.item_type, R.id.item_lac, R.id.item_cid, R.id.item_time_stamp});
        lv_list.setAdapter(listAdapter);

        btn_start.setOnClickListener(new OnClickListener(){
			//@Override
			public void onClick(View v) {
				if (lbsManager!=null)
					lbsManager.startLBS();
			}
        });
        btn_stop.setOnClickListener(new OnClickListener(){
			//@Override
			public void onClick(View v) {

			}
        }); 
        
        //addLine("GSM", 1, 2, 3);
    }

    private void addLine(String type, int lac, int cid, long timestamp){
		HashMap<String,String> map=new HashMap<String,String>();
		map.put("type", type);
		map.put("lac",   Integer.toString(lac));
		map.put("cid",   Integer.toString(cid));
		map.put("timestamp", Long.toString(timestamp));
		
		listData.add(map);
		listAdapter.notifyDataSetChanged();
    }

    public void show(Vector<GSMCell> gsmCells, Vector<CDMACell> cdmaCells){
    	listData.clear();
    	
    	for (GSMCell v: gsmCells)
    		addLine("GSM", v.lac, v.cid, v.time);
//    	if (cdmaCells.size()>0){
//    		for (int i=0;i<cdmaCells.size();i++)
//    			addLine("GSM", cdmaCells.get(i).lac, cdmaCells.get(i).cid, cdmaCells.get(i).time);
//    		
//    	}
    }
}